<?php


namespace app\api\model;


use think\Cache;
use think\Model;

class SourceMaterialConfig extends Model
{

    //自动写入时间
    protected $autoWriteTimestamp = true;

    /**
     * 时间格式化
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i:s';

    private static $expireTime = 86400;

    private static $getSourceMaterialConfigInfoBySecondaryClassificationKey = 'getSourceMaterialConfigInfoBySecondaryClassificationKey:';

    //根据二级分类别名获取素材详情
    public static function getSourceMaterialConfigInfoBySecondaryClassification($secondaryClassification)
    {
        $cacheKey = self::$getSourceMaterialConfigInfoBySecondaryClassificationKey . $secondaryClassification;
        $sourceMaterialInfo = Cache::store('redis')->get($cacheKey);
        $sourceMaterialInfo = [];//TODO 暂时不用缓存
        if (empty($sourceMaterialInfo)) {
            $sourceMaterialInfo = self::get(['secondary_classification' => $secondaryClassification]);
            Cache::store('redis')->set($cacheKey, $sourceMaterialInfo,self::$expireTime);
        }
        return $sourceMaterialInfo;
    }

}